package com.driving.code.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 项目开发作者：喜欢编程的代先生
 * 日期：2021/6/6 0:14
 * 当前类的描述信息：
 * 完成页面的跳转
 */
@Controller
@RequestMapping("page")
public class PageController {

    /**
     * 跳转到网站的前台首页面
     * @return
     */
    @RequestMapping("frontIndex")
    public String frontIndex(){
        return "front/index";
    }

    /**
     * 跳转到网站的登录角色选择的页面
     * @return
     */
    @RequestMapping("loginSelect")
    public String loginSelect(){
        return "front/login-select";
    }

    /**
     * 跳转到网站的注册角色选择的页面
     * @return
     */
    @RequestMapping("registerSelect")
    public String registerSelect(){
        return "front/register-select";
    }

    /**
     * 跳转到学员登录的页面
     * @return
     */
    @RequestMapping("learnerLogin")
    public String learnerLogin(){
        return "front/learner-login";
    }

    /**
     * 跳转到学员注册的页面
     * @return
     */
    @RequestMapping("learnerRegister")
    public String learnerRegister(){
        return "front/learner-register";
    }

    /**
     * 跳转到我的信息页面
     * @return
     */
    @RequestMapping("learnerInformation")
    public String learnerInformation(){
        return "front/learner-information";
    }


    /**
     * 去科目一的顺序练习页面
     * @return
     */
    @RequestMapping("subjectOneSequence")
    public String subjectOneSequence(){
        return "front/subject-one-sequence";
    }

    /**
     * 去科目四的顺序练习页面
     * @return
     */
    @RequestMapping("subjectFourSequence")
    public String subjectFourSequence(){
        return "front/subject-four-sequence";
    }

    /**
     * 去科目一的专项练习的专题选择页面
     * @return
     */
    @RequestMapping("subjectOneSpecial")
    public String subjectOneSpecial(){
        return "front/subject-one-special";
    }

    /**
     * 去科目一单项选择专项练习页面
     * @return
     */
    @RequestMapping("subjectOneUniterming")
    public String subjectOneUniterming(){
        return "front/subject-one-uniterming";
    }

    /**
     * 去科目一多项选择专项练习页面
     * @return
     */
    @RequestMapping("subjectOneMultipleChoice")
    public String subjectOneMultipleChoice(){
        return "front/subject-one-multiple-choice";
    }

    /**
     * 去科目一判断题专项练习页面
     * @return
     */
    @RequestMapping("subjectOneTrueOrFalse")
    public String subjectOneTrueOrFalse(){
        return "front/subject-one-true-or-false";
    }

    /**
     * 去科目四的专项练习的专题选择页面
     * @return
     */
    @RequestMapping("subjectFourSpecial")
    public String subjectFourSpecial(){
        return "front/subject-four-special";
    }

    /**
     * 去科目四单项选择专项练习页面
     * @return
     */
    @RequestMapping("subjectFourUniterming")
    public String subjectFourUniterming(){
        return "front/subject-four-uniterming";
    }

    /**
     * 去科目四多项选择专项练习页面
     * @return
     */
    @RequestMapping("subjectFourMultipleChoice")
    public String subjectFourMultipleChoice(){
        return "front/subject-four-multiple-choice";
    }

    /**
     * 去科目四判断题专项练习页面
     * @return
     */
    @RequestMapping("subjectFourTrueOrFalse")
    public String subjectFourTrueOrFalse(){
        return "front/subject-four-true-or-false";
    }


    /**
     * 去科目一的随机练习页面
     * @return
     */
    @RequestMapping("subjectOneRandom")
    public String subjectOneRandom(){
        return "front/subject-one-random";
    }

    /**
     * 去科目四的随机练习页面
     * @return
     */
    @RequestMapping("subjectFourRandom")
    public String subjectFourRandom(){
        return "front/subject-four-random";
    }

    /**
     * 去科目一的易错题练习页面
     * @return
     */
    @RequestMapping("subjectOneMistakable")
    public String subjectOneMistakable(){
        return "front/subject-one-mistakable";
    }

    /**
     * 去科目四的易错题练习页面
     * @return
     */
    @RequestMapping("subjectFourMistakable")
    public String subjectFourMistakable(){
        return "front/subject-four-mistakable";
    }

    /**
     * 去科目一的模拟考试页面
     * @return
     */
    @RequestMapping("subjectOneTest")
    public String subjectOneTest(HttpServletRequest request){
        //从上下文对象中获取管理员设置的时间
        ServletContext servletContext = request.getServletContext();
        Integer time_limit = (Integer) servletContext.getAttribute("time_limit_one");
        if (time_limit == null){
            //默认的时间是120秒
            time_limit = 120;
        }
        request.setAttribute("time_limit",time_limit);

        return "front/subject-one-test";
    }

    /**
     * 去科目四的模拟考试页面
     * @return
     */
    @RequestMapping("subjectFourTest")
    public String subjectFourTest(HttpServletRequest request){
        //从上下文对象中获取管理员设置的时间
        ServletContext servletContext = request.getServletContext();
        Integer time_limit = (Integer) servletContext.getAttribute("time_limit_four");
        if (time_limit == null){
            //默认的时间是120秒
            time_limit = 120;
        }
        request.setAttribute("time_limit",time_limit);
        return "front/subject-four-test";
    }


    /**
     * 去 考试结果的页面
     * @return
     */
    @RequestMapping("testResult/{score}/{userTIme}/{subject}")
    public String testResult(@PathVariable(value = "score",required = true) Integer score,
                             @PathVariable(value = "userTIme",required = true) Integer userTIme,
                             @PathVariable(value = "subject",required = true) String subject,
                             HttpServletRequest request){
        request.setAttribute("score",score);
        request.setAttribute("userTIme",userTIme);
        if (score > 1){
            request.setAttribute("image","/image/front/mlss-excellent.png");
        }else {
            request.setAttribute("image","/image/front/mlss-bad.png");
        }
        return "front/test-result";
    }

    /**
     * 去后台登录的页面
     * @return
     */
    @RequestMapping("backLogin")
    public String backLogin(){
        return "back/back-login";
    }

    /**
     * 去后台主页面
     * @return
     */
    @RequestMapping("backIndex")
    public String backIndex(){
        return "back/back-index";
    }

    /**
     * 全部试题
     * @return
     */
    @RequestMapping("backSeeAllQuestion")
    public String backSeeAllQuestion(){
        return "back/back-see-all-question";
    }

    /**
     * 添加问题
     * @return
     */
    @RequestMapping("backAddQuestion")
    public String backAddQuestion(){
        return "back/back-add-question";
    }

    /**
     * 考试管理的页面
     * @return
     */
    @RequestMapping("testManage")
    public String testManage(){
        return "back/test-manage";
    }

    /**
     * 未登录
     * @return
     */
    @RequestMapping("unlogin")
    public String unlogin(){
        return "common/unlogin";
    }

    /**
     * 未授权
     * @return
     */
    @RequestMapping("unauthorized")
    public String unauthorized(){
        return "common/unauthorized";
    }
}
